<template>
    <el-container class="home-container">
      <!-- 首部 -->
      <el-header>
        <div>
        <!-- <img src="../assets/css/logo.jpg" alt=""> -->
        <span>后台算命系统</span>
      </div>
      <div class="enclose" @click="logout">
        <span class="top"></span>
        <span class="right"></span>
        <span class="bottom"></span>
        <span class="left"></span>
        <p>LOGOUT</p>
      </div>
      </el-header>
      <!-- 主体 -->
      <el-container>
      <!-- 侧边栏 -->
      <el-aside :width="'56px'">
        <!-- 折叠按钮 -->
        <div class="toggle-button"> </div>
        <!-- 侧边栏菜单 -->
        <el-menu background-color="rgba(255,255,255,.0)" text-color="whitesmoke" active-text-color="#409EFF"
        :unique-opened="true" :collapse="true"
        :router="true" :default-active="activePath">
            <!-- 一级菜单 -->
            <el-submenu :index="item.id + ''" v-for="item in menulist" :key="item.id">
              <template slot="title">
                <i :class="iconsObj[item.id]"></i>
                <!-- 菜单名 -->
                <span>{{item.authName}}</span>
              </template>
              <!-- 二级菜单 -->
              <!-- 拼接路由导航字符串 -->
              <el-menu-item :index="'/' + subItem.path" v-for="subItem in item.children"
              :key="subItem.id" @click="saveNavState('/' + subItem.path)">
                <template slot="title">
                  <i class="el-icon-menu"></i>
                  <span>{{subItem.authName}}</span>
                </template>
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
          <!-- 路由占位符 -->
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
</template>

<script>
export default {
  data() {
    return {
      // 挂载左侧菜单数据
      menulist: [],
      // 菜单栏图标K为一级菜单ID,V为图标
      iconsObj: {
        104: 'iconfont icon-user',
        103: 'iconfont icon-tijikongjian',
        101: 'iconfont icon-shangpin',
        102: 'iconfont icon-danju',
        105: 'iconfont icon-baobiao'
      },
      // // 是否折叠
      // isCollapse: false,
      // 激活链接地址
      activePath: ''
    }
  },
  created() {
    this.getMenuList()
    this.activePath = window.sessionStorage.getItem('activePath')
  },
  methods: {
    logout () {
      window.sessionStorage.clear()
      this.$router.push('/login')
    },
    // 获取左侧菜单
    async getMenuList() {
      const { data: res } = await this.$http.get('menus')
      if (res.meta.status !== 200) return this.$message.error(res.meta.msg)
      this.menulist = res.data
      console.log(res.data)
    },
    // 默认激活菜单选项
    saveNavState(activePath) {
      window.sessionStorage.setItem('activePath', activePath)
      this.activePath = activePath
    }
  }
}
</script>

<style lang="less" scoped>
.home-container {
  background-image: url('../assets/css/bgp6.jpg');
  background-repeat: no-repeat;
  background-attachment: fixed;
  min-height: 100%;
}

.el-header {
  background-color: transparent;
  display: flex;
  justify-content: space-between;
  padding-left: 0;
  align-items: center;
  color: #fff;
  font-size: 20px;
  > div {
    display: flex;
    align-items: center;
    span {
      margin-left: 15px;
    }
  }
}
.el-aside {
  overflow: hidden;
  background-color: transparent;
  .el-menu {
    border-right: none;
  }
}

.el-main {
  background-color: transparent;
  overflow: hidden;
  z-index: 5;
}

//图标距离文字1像素
// .iconfont {
//   // margin-right: 10px;
// }

// 折叠按钮
.toggle-button {
  height: 120px;
  background-color:transparent;
}

// 退出按钮
        .enclose{
            position: relative;
            width: 55px;
            height: 35px;
            text-align: center;
            color: aliceblue;
            background: rgba(241, 241, 241, .0);
            text-shadow: 0 0 0 rgb(94, 190, 253);
            cursor: pointer;
            transition: all 1s;
            font-size: 12px;
        }

        .enclose:hover{
            text-shadow: 0 0 10px rgb(94, 190, 253);
        }

        .top,
        .right,
        .bottom,
        .left{
            position: absolute;
            background: rgb(94, 190, 253);
            // #2097ef
            box-shadow: 0 0 10px rgb(94, 190, 253);
            transition: all .1s;
        }

        .top{
            top: 0;
            left: -26px;
            width: 0;
            height: 1px;
            transition-delay: .3s;
        }

        .enclose:hover>.top{
            width: 70px;
            transition-delay: 0s;
        }

        .right{
            top: 0;
            right: -5px;
            width: 1px;
            height: 0;
            transition-delay: .2s;
        }

        .enclose:hover>.right{
            height: 35px;
            transition-delay: .1s;
        }

        .bottom{
            bottom: 0;
            right: -4px;
            width: 0;
            height: 1px;
            transition-delay: .1s;
        }

        .enclose:hover>.bottom{
            width: 70px;
            transition-delay: .2s;
        }

        .left{
            bottom: 0;
            left: -26px;
            width: 1px;
            height: 0;
        }

        .enclose:hover>.left{
            height: 35px;
            transition-delay: .3s;
        }
</style>
